
const fs = require('fs').promises;
const path = require('path');
const isExist = require('../lib/helper/utils').isExist;

const httUrlTest = require('./httpUrl');
const sshUrlTest = require('./sshUrl');
const requestTest = require('./request');

const flag = new Proxy({ count: 0 }, {
  set(target, prop, value) {
    Reflect.set(...arguments);
    if (value === 3) process.exit();
  }
});

const REPO_ROOT = path.join(__dirname, '.tmp');

(async () => {
  if (isExist(REPO_ROOT)) {
    await fs.rmdir(REPO_ROOT, { recursive: true }); // node v12.10.0 才开始支持recursive
    await fs.mkdir(REPO_ROOT);
  }

  httUrlTest(REPO_ROOT, flag);
  sshUrlTest(REPO_ROOT, flag);
  await requestTest(REPO_ROOT, flag)
})();
